URL = "http://downloads.sourceforge.net/project/freeglut/freeglut/freeglut-%(VERSION)s.tar.gz"
VERSIONS = ["2.6.0"]
DEFAULT_VERSION = "2.6.0"

from source.builders import VisualStudioBuilder, ConfigureMakeBuilder
import os

class FreeGlutBuilder( VisualStudioBuilder ):
  """ subclass of ConfigureMakeBuilder with custom configure step """
              
  def configure(self):
    if not self.machine.isVS2008():
      print("Manual build needed. VS2008 is supported")
      exit()

  def make(self):  
    os.chdir( self.extractedpath+"" )

    if self.machine.bits == 64:
      self.convertProjTo64("VisualStudio2008\\freeglut.vcproj")
      self.convertProjTo64("VisualStudio2008Static\\freeglut.vcproj")
      self.convertSolutionTo64("VisualStudio2008\\freeglut.sln")
      self.convertSolutionTo64("VisualStudio2008Static\\freeglut.sln")

    self.debug = True  
    self.call_devenv("VisualStudio2008\\freeglut.sln", "freeglut")
    self.call_devenv("VisualStudio2008Static\\freeglut.sln", "freeglut")
    self.debug = False  
    self.call_devenv("VisualStudio2008\\freeglut.sln", "freeglut")
    self.call_devenv("VisualStudio2008Static\\freeglut.sln", "freeglut")

  def install(self):
    bindir = self.installpath() + "/bin"
    libdir = self.installpath() + "/lib"
    includedir = self.installpath() + "/include"

    #todo add a postfix for debug libs
    #dll binary
    self.copyfile( "VisualStudio2008/Release/freeglut.dll", bindir )
    #dynamic link lib
    self.copyfile( "VisualStudio2008/Release/freeglut.lib", libdir )
    #static lib
    self.copyfile( "VisualStudio2008Static/Release/freeglut_static.lib", libdir )
    self.copyfile( "VisualStudio2008Static/Debug/freeglut_static.lib", libdir+"//debug" )

    #headers
    self.copydir("include", includedir )

def decider( machine, dirs ):
  return { "Linux" : ConfigureMakeBuilder,
           "Windows" : FreeGlutBuilder }[machine.platform]

BUILDER = decider

